#define BOOST_TEST_MODULE testElementItemUserState

#include <boost/test/unit_test.hpp>

#include "common/elements/element_maker.h"
#include "common/elements/item_user_state.h"

BOOST_AUTO_TEST_CASE(testItemUserStateJson)
{
    auto first = std::make_shared<Elements::ItemUserState>();
    first->setId(1);
    first->setItemId(2);
    first->setUserId(3);
    first->setStateId(4);

    const std::time_t timestamp = std::time(nullptr);
    first->setTimestamp(timestamp);

    const auto json = first->toJsonString();
    const Elements::ElementPtr second(Elements::fromJsonString(json));
    BOOST_CHECK(first->isSame(second.get()));

    const auto third = std::static_pointer_cast<Elements::ItemUserState>(second);
    BOOST_CHECK(1 == third->id());
    BOOST_CHECK(2 == third->itemId());
    BOOST_CHECK(3 == third->userId());
    BOOST_CHECK(4 == third->stateId());
    BOOST_CHECK(timestamp == third->timestamp());
}
